home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 27.zip / BS1 part 27 / PhonepakV2_d1.adf / rexx / Forwarding.ppak < prev    next >
Text File  |  1993-04-28  |  7KB  |  171 lines

  1. /****************************************************************************/
  2. /*  PhonePak ARexx script for Message Forwarding                            */
  3. /*                                                                          */
  4. /*  LineMan is expecting a result string consisting of a number and a       */
  5. /*  message.  PhonePak's schedule listing can display a message up to 15    */
  6. /*  characters long.  If the number is less than zero, the error is         */
  7. /*  considered fatal and no further attempts will be made.  Zero means      */
  8. /*  success; the forwarding liability will be reset.  Greater than zero     */
  9. /*  represents the number of minutes to wait before trying again; this is   */
  10. /*  therefore a retriable error.                                            */
  11. /****************************************************************************/
  12.  
  13. /***************/
  14. /*  Constants  */
  15. /***************/
  16.  
  17. interval = 10                           /* Minutes before next attempt */
  18. maxlines = 5                            /* Maximum number of phone lines */
  19. maxattempts = 15                        /* Maximum number of retries */
  20.  
  21. /****************************************************************************/
  22.  
  23. options failat 101
  24. options results
  25.  
  26. arg PhoneNumber                             /* Get args handed in by LineMan */
  27. Mailbox = GetDirName(PRAGMA('d'))           /* Get mailbox name (current dir) */
  28. Upper Mailbox                               /* Make sure its upper case */
  29.  
  30. /***********************************/
  31. /*  Try to find an available line  */
  32. /***********************************/
  33.  
  34. x = 1
  35. do forever
  36.     PortName = 'LINEMAN.' || x              /* Assemble the port name */
  37.     if show('P', PortName) then do          /* See if the port is present */
  38.         address value PortName              /* Modify host address */
  39.         SETMAILBOX Mailbox                  /* Get mailbox info */
  40.         if rc = 0 then do        
  41.             if word(result,3) = IN then
  42.                 exit interval "'MB is marked IN'"
  43.             else
  44.                 call Forward()              /* Only returns if call should */
  45.             end                             /* be attempted on another line */
  46.         else if rc != 98 & rc != 99 then
  47.             exit "-1 'Script error'"        /* Outer quotes get stripped */
  48.         end
  49.     if x = maxlines then
  50.         exit interval "'Line not avail'"    /* Outer quotes get stripped */
  51.     else
  52.         x = x + 1                           /* Increment line # and continue */
  53.     end
  54.  
  55. /*********************************/
  56. /*  SUBROUTINE                   */
  57. /*  Attempt to forward messages  */
  58. /*********************************/
  59.  
  60. Forward:
  61.     OpString = '<O><D>' PhoneNumber '<C><W15>'
  62.     OPERATOR OpString                           /* Dial the phone number */
  63.     DialResult = rc
  64.  
  65.     if DialResult ~= 0 then                     /* Hang up on error */
  66.         Operator '<H>' 
  67.  
  68.     select
  69.         when DialResult = -3 then               /* Make sure phone # is 'raw' */
  70.             exit "-1 'Procedure error'"      
  71.         when DialResult = -2 then               /* Probably a missing message */
  72.             exit "-1 'I/O error'"      
  73.         when DialResult = -1 then       
  74.             exit "-1 'Syntax error'"      
  75.  
  76.         when DialResult = 0 then     
  77.             nop
  78.         when DialResult = 1 then     
  79.             exit interval "'Resource error'"      
  80.         when DialResult = 2 then     
  81.             exit interval "'Local pickup'"      
  82.         when DialResult = 4 then     
  83.             return      
  84.         when DialResult = 5 then     
  85.             exit interval "'No dialtone'"      
  86.         when DialResult = 6 then do    
  87.             if TryAgain() = TRUE then           /* Limit number of attempts */
  88.                 exit interval "'No answer'"      
  89.             else
  90.                 exit "-1 'Hit retry limit'"      
  91.             end
  92.  
  93.         when DialResult = 8 then do     
  94.             if TryAgain() = TRUE then           /* Limit number of attempts */
  95.                 exit interval "'Busy signal'"      
  96.             else
  97.                 exit "-1 'Hit retry limit'"      
  98.             end
  99.  
  100.         when DialResult = 98 | DialResult = 99 then     
  101.             return      
  102.         otherwise
  103.             exit "-1 'Fatal error'"      
  104.         end
  105.  
  106.     setclip(Mailbox || ATTEMPTS, 0)             /* Reset busy attempts */
  107.  
  108. /****************************************************************************/
  109. /* The called party will hear "x new messages.  Please enter your password  */
  110. /* now" upon answering the phone.  If you would like to make this script    */
  111. /* a little more sophisticated, you could insert a PLAYBACK command here    */
  112. /* to play a message that says something like "This is an automated call    */
  113. /* for John; please call him to the phone."  If you put the message in      */
  114. /* in John's mailbox, the filename in the PLAYBACK command will not require */
  115. /* a path specification, since the current directory is already set to      */
  116. /* John's mailbox.  You might play the message three times or so, while you */
  117. /* wait for John to press 1 or some other DTMF code to indicate that the    */
  118. /* script should proceed.  You could even play a message that tells the     */
  119. /* called party what to do if John is not available (e.g., call back in     */
  120. /* thirty minutes, sixty minutes, or not at all), modifying the script's    */
  121. /* exit code according to the called party's response.                      */
  122. /****************************************************************************/
  123.  
  124.     REMOTEACCESS Mailbox                        /* Initiate remote access */
  125.     RAResult = rc                               /* Stash result */
  126.     Operator '<H>'                              /* Hang up when finished */
  127.  
  128.     select
  129.         when RAResult = -3 then
  130.             exit "-1 'Bad Password'"      
  131.         when RAResult = -2 then            
  132.             exit "-1 'I/O error'"      
  133.         when RAResult = -1 then       
  134.             exit "-1 'Syntax error'"      
  135.         when RAResult = 1 then     
  136.             exit interval "'Resource error'"      
  137.         otherwise
  138.             exit                                /* Success! */                                  
  139.         end
  140.  
  141. /***********************************/
  142. /*  SUBROUTINE                     */
  143. /*  Get name of current directory  */
  144. /***********************************/
  145.  
  146. GetDirName:
  147.     path = arg(1)
  148.     n = lastpos("/",path)
  149.     
  150.     if n=0 then
  151.         n = lastpos(":",path)
  152.         
  153.     return substr(path, n+1)
  154.  
  155. /***********************************/
  156. /*  SUBROUTINE                     */
  157. /*  Determine if retries remain    */
  158. /***********************************/
  159.  
  160. TryAgain:
  161.     x = getclip(Mailbox || ATTEMPTS)
  162.     if x = '' then x = 0
  163.     x = x + 1        
  164.     if x = maxattempts then do
  165.         x = 0
  166.         setclip(Mailbox || ATTEMPTS, x)
  167.         return FALSE
  168.         end
  169.     setclip(Mailbox || ATTEMPTS, x)
  170.     return TRUE      
  171.